package com.pan.admin.common.utils;

import com.pan.admin.common.constant.module.StatisticEnum;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * 统计相关
 * @author Pan
 */
public class StatisticUtils {

    /**
     * 获取所需填充时间
     *
     * @param statisticEnum
     * @return List<String>
     */
    public static List<String> getFillTime(StatisticEnum statisticEnum) {
        List<String> time = new ArrayList<>();
        LocalDate now = LocalDate.now();
        int dayOfMonth = now.getDayOfMonth();
        int currentMonth = now.getMonth().getValue();

        switch (statisticEnum) {
            case HOURLY:
                for (int i = 0; i < 24; i++) {
                    String value = String.valueOf(i);
                    if (i < 10) {
                        value = "0" + value;
                    }
                    time.add(value);
                }
                break;
            case DAILY:
                for (int i = 1; i <= dayOfMonth; i++) {
                    LocalDate localDate = now.plusDays(i - dayOfMonth);
                    time.add(localDate.format(DateTimeFormatter.ISO_DATE));
                }
                break;
            case MONTHLY:
                for (int i = 1; i <= currentMonth; i++) {
                    if (i < 10) {
                        time.add(new StringBuilder().append(now.getYear()).append("-").append("0" + i).toString());
                    } else {
                        time.add(new StringBuilder().append(now.getYear()).append("-").append(i).toString());
                    }
                }
                break;
            case NOW:
                if (currentMonth < 10) {
                    time.add(new StringBuilder().append(now.getYear()).append("-").append("0" + currentMonth).append("-").append(dayOfMonth).toString());
                } else {
                    time.add(new StringBuilder().append(now.getYear()).append("-").append(currentMonth).append("-").append(dayOfMonth).toString());
                }
                break;
        }
        return time;
    }
}
